$(document).ready(function() {  
    $('#file_upload').uploadify({  
        'swf'       : '/static/uploadify/uploadify.swf',
        'uploader'  : '/uploadFile/',  
        'auto'      : true, 
        'requeueErrors':false,  
        'buttonText':'上传',     
        'removeCompleted':true,         
        'onInit': function () {},  
        'onError' : function (event,ID,fileObj,errorObj) {  
            $('#id_span_msg').html("上传失败，错误码:"+errorObj.type+" "+errorObj.info);  
        },  
        'onSelect': function (e, queueId, fileObj) {  
            $('#id_span_msg').html("");  
        },  
        'onCancel'    : function(event,ID,fileObj,data) {  

        }, 
        'onUploadSuccess': function(file,data,response) {
            console.log(data);
        }  
    });

    $('.deleteFile').click(function() {
        var file=$(this).parent().attr("id")
        console.log(file);
        $.ajax({
            url: '/deleteFile/',
            type: 'POST',
            dataType: 'json',
            data: {
                file:file
            },
            success:function(callback){
                console.log(callback);
            }
        })
        .done(function() {
            console.log('success');
            window.location.reload();
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });
    });

    $('.downloadFile').click(function() {
        var file=$(this).parent().attr("id");
        console.log(file);
        window.location="/downloadFile/?file="+file;
    });
});